package com.panshi.controller;

import com.panshi.service.IRoleService;
import com.panshi.vo.KeyValueVO;
import com.panshi.vo.ResultVO;
import com.panshi.vo.RoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(path = "role")
public class RoleController {

    @Autowired
    private IRoleService iRoleService;


    @GetMapping("/view/initRoleList")
    @ResponseBody
    public ResultVO<List<KeyValueVO>> initRoleList(){
        return iRoleService.initRoleListInfo();
    }

    @GetMapping("/view/getRoleSelectByUserId/{userId}")
    @ResponseBody
    public ResultVO<List<KeyValueVO>> getRoleSelectByUserId(@PathVariable long userId){
        return iRoleService.getRoleSelectByUserId(userId);
    }

    @GetMapping("/view/roleList")
    @ResponseBody
    public ResultVO<List<RoleVO>> roleList(){
        int status = -1;
        return iRoleService.findRoleList(status);
    }

    @PutMapping("/edit/status")
    @ResponseBody
    public ResultVO<String> editRoleStatus(@RequestBody RoleVO roleVO){
        return iRoleService.editRoleStatus(roleVO);
    }

    @DeleteMapping("/del/{roleId}")
    @ResponseBody
    public ResultVO<String> delRoleInfo(@PathVariable long roleId){
        return iRoleService.delRoleInfo(roleId);
    }

    @PostMapping("/add")
    @ResponseBody
    public ResultVO<String> addRoleInfo(@RequestBody RoleVO roleVO){
        return iRoleService.addRoleInfo(roleVO);
    }

    @PutMapping("/edit")
    @ResponseBody
    public ResultVO<String> editRoleInfo(@RequestBody RoleVO roleVO){
        return iRoleService.editRoleInfo(roleVO);
    }

    @GetMapping("/test")
    @ResponseBody
    public String test(){
        return "鎏金哇酷烈库";
    }
}
